# Maintainer: Justin Kromlinger <hashworks@archlinux.org>

pkgname=opensearch-ml-commons-plugin
pkgver=2.11.0.0
pkgrel=1
_opensearchver=2.11.0
_jdkver=11
pkgdesc="OpenSearch Machine Learning Commons Plugin"
arch=('loong64' 'x86_64')
url="https://opensearch.org/docs/latest/ml-commons-plugin/index/"
license=('Apache')
depends=("opensearch=${_opensearchver}")
makedepends=("java-environment=${_jdkver}" 'unzip')
source=(
  "${pkgname}-${pkgver}.tar.gz::https://github.com/opensearch-project/ml-commons/archive/${pkgver}.tar.gz"
)
sha256sums=('77798cfdc7b666d26152dfcc1c67a7460801848d9065858e00ed59266d1179f1')

build() {
  cd "ml-commons-${pkgver}"
  export JAVA_HOME="/usr/lib/jvm/java-${_jdkver}-openjdk"
  export PATH="/usr/lib/jvm/java-${_jdkver}-openjdk/bin:$PATH"
  export GRADLE_OPTS="-Dbuild.snapshot=false -Dopensearch.version=${_opensearchver}"
  ./gradlew build \
    --exclude-task ":opensearch-ml-algorithms:jacocoTestReport" \
    --exclude-task ":opensearch-ml-algorithms:jacocoTestCoverageVerification" \
    --exclude-task ":opensearch-ml-common:jacocoTestReport" \
    --exclude-task ":opensearch-ml-common:jacocoTestCoverageVerification" \
    --exclude-task ":opensearch-ml-client:jacocoTestReport" \
    --exclude-task ":opensearch-ml-client:jacocoTestCoverageVerification"
}

package() {
  install -dm755 "${pkgdir}/usr/share/opensearch/plugins/opensearch-ml"
  cd "${pkgdir}/usr/share/opensearch/plugins/opensearch-ml"
  unzip "${srcdir}/ml-commons-${pkgver}/plugin/build/distributions/opensearch-ml-${pkgver}.zip"

  install -Dm644 "${srcdir}/ml-commons-${pkgver}/LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
